package com.bruce.service.impl;

import com.bruce.Common.Resultcode;
import com.bruce.bean.Colleage;
import com.bruce.bean.Course;
import com.bruce.dao.CollegeDao;
import com.bruce.dao.MajorDao;
import com.bruce.dao.impl.CollegeDaoImpl;
import com.bruce.dao.impl.MajorDaoImpl;
import com.bruce.service.collegeService;

import java.util.List;

/**
 * @author cc
 * @date 2021/7/20 17:57
 * @Description
 */

public class collegeServiceImpl implements collegeService  {

    MajorDao majorDao= new MajorDaoImpl();
    CollegeDao collegeDao = new CollegeDaoImpl();
    @Override
    public List<Colleage> findColleges() {
        return collegeDao.findColleges();
    }

    @Override
    public int insertCourse(Course course) {
        //系名字
        String majorName = majorDao.findMajorName(Integer.parseInt(course.getBelongcoll()));
        //专业名称
        String collegestitle = collegeDao.findcollegestitle(Integer.parseInt(course.getBelongcoll()));
        course.setBelongpro(majorName);
        course.setBelongcoll(collegestitle);
        int i = collegeDao.insertCourse(course);
        if (i<1){
            throw new RuntimeException(Resultcode.Add_Error.getMess());
        }
        return i;
    }
}
